const Router = require("koa-router");
const fs = require("fs");
const path = require("path");

const router = new Router();

// 前端路由重定向
const indexPath = path.join(__dirname, "../../../public/index.html");

const handleRedirect = async (ctx) => {
  console.log("Index path:", indexPath); // 打印路径
  ctx.type = "html";
  ctx.body = fs.createReadStream(indexPath);
};

// 匹配所有非 /api 开头的路径
router.get(/^(?!\/api).*/, handleRedirect);

module.exports = router;
